# coding:utf8

import pymysql.cursors


def select_from_mysql():
    conn = pymysql.connect(host='localhost',
                           user='root',
                           password='root',
                           db='omdb2',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)

    try:
        with conn.cursor() as cursor:
            sql = "SELECT `id`, `name` FROM `t_names` LIMIT 0, 10"
            cursor.execute(sql)
            result = cursor.fetchall()
            for x in result:
                print(x)
    finally:
        conn.close()


if __name__ == '__main__':
    select_from_mysql()



